home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 1 / PC Actual CD 01.iso / f1 / func3d.arj / FUENTE / EJEMPLOS.CP_ / EJEMPLOS.CP
Encoding:
Text File  |  1994-05-06  |  7.1 KB  |  276 lines

  1. //
  2. //   Fichero: EJEMPLOS.CPP
  3. //
  4. //   Versi≤n: 1.0
  5. //     Autor: Antonio M. EstΘvez Lorenzo
  6. // Prop≤sito: Muestra los ejemplos de superficies
  7. //            contenidos en el fichero FUNCWIN.SUP
  8. //
  9.  
  10. #include <windows.h>
  11. #include <owl.h>
  12. #pragma  hdrstop
  13.  
  14. #include "Ejemplos.h"
  15. #include "Child.h"
  16. #include "strings.h"
  17. #include "Errores.ids"
  18. #include "Ayuda.ids"
  19.  
  20. typedef struct
  21. {
  22.    FuncStr Nombre,EcuX,EcuY,EcuZ;
  23.    FuncStr IntvA,IntvB,Escala,Origen;
  24.    FuncStr AngIni;
  25.    FuncStr Nodos;
  26. } TEjemplo;
  27.  
  28. struct TDatEjemplo
  29. {
  30.    TDatEjemplo *Sig,*Ant;
  31.    TEjemplo Datos;
  32. };
  33.  
  34. static char NombreStr[]= "Nombre";
  35. static char EcuXStr[]  = "X";
  36. static char EcuYStr[]  = "Y";
  37. static char EcuZStr[]  = "Z";
  38. static char IntvAStr[] = "Intv A";
  39. static char IntvBStr[] = "Intv B";
  40. static char EscalaStr[]= "Escala";
  41. static char OrigenStr[]= "Origen";
  42. static char AngIniStr[]= "Angulo";
  43. static char NodosStr[] = "Nodos";
  44. static int  MatId[10]= {edFunc,edEcuX,edEcuY,edEcuZ,edInfX,edInfY,
  45.                        edCoordX,edCoordY,edCoordZ,edNodosX};
  46.  
  47. /* ProfileStream */
  48.  
  49. class ProfileStream: public ifstream
  50. {
  51.     long Posicion;
  52. public:
  53.     ProfileStream(char *Nombre) : ifstream(Nombre) {Posicion= 0;};
  54.     BOOL BuscaSeccion(char *Sec);
  55.     void BuscaClave(char *Clave, char *Str, int Long, char *Defect);
  56. };
  57.  
  58. BOOL ProfileStream::BuscaSeccion(char *Sec)
  59. {
  60.    BOOL Encontrado;
  61.    char Seccion[80];
  62.    char Linea[256];
  63.  
  64.    clear();
  65.    seekg(Posicion);
  66.    wsprintf(Seccion,"[%s]",Sec);
  67.    Encontrado= FALSE;
  68.    while(!Encontrado && !bad() && !eof())
  69.    {
  70.       getline(Linea,LongFunc);
  71.       Encontrado= StrEqu(Linea, Seccion);
  72.    }
  73.    if(Encontrado)
  74.       Posicion= tellg();
  75.    return Encontrado;
  76. }
  77.  
  78. void ProfileStream::BuscaClave(char *Clave, char *Str, int Long, char *Defect)
  79. {
  80.    char Linea[256];
  81.    char tmpStr[256];
  82.    BOOL Encontrado= FALSE;
  83.    BOOL Seguir= TRUE;
  84.  
  85.    clear();
  86.    seekg(Posicion);
  87.    do{
  88.       getline(Linea,LongFunc);
  89.       if(Linea[0]== '[')
  90.          Seguir= FALSE;
  91.       else
  92.       {
  93.          StrSep(Linea,tmpStr,'=');
  94.          Encontrado= StrEqu(Linea, Clave);
  95.       }
  96.    }while(Seguir && !Encontrado && !bad() && !eof());
  97.    if(Encontrado)
  98.       StrMov(Str, tmpStr, Long);
  99.    else
  100.       StrMov(Str, Defect, Long);
  101. }
  102.  
  103.  
  104. /* TDlgEjemplos */
  105.  
  106. TDatEjemplo *TDlgEjemplos::Primer;
  107. TDatEjemplo *TDlgEjemplos::Ultimo;
  108. TDatEjemplo *TDlgEjemplos::Actual;
  109.  
  110. TDlgEjemplos::TDlgEjemplos(PTWindowsObject parent, PTModule module)
  111.              :TWindDlg(parent, dgEjemplos, module)
  112. {
  113.    for(int i= 0; i< sizeof(MatId)/sizeof(MatId[0]); i++)
  114.       new TStatic(this,MatId[i],LongFunc)->EnableTransfer();
  115.    ChildWind= new TChildEjemplo(this);
  116.    DisableTransfer();
  117. }
  118.  
  119. void TDlgEjemplos::SetupWindow()
  120. {
  121.    TWindDlg::SetupWindow();
  122.  
  123.    RECT Rect;
  124.    GetWindowRect(HWindow, &Rect);
  125.    ShowWindow(ChildWind->HWindow, SW_HIDE);
  126.    ChildWind->Move(Rect.left+6, Rect.top+70);
  127.    Muestra(Actual);
  128. }
  129.  
  130. BOOL TDlgEjemplos::CanClose()
  131. {
  132.    ChildWind->Ejemplo= FALSE;
  133.    return ChildWind->CanClose();
  134. }
  135.  
  136. BOOL TDlgEjemplos::HayEjemplos(char *ProgDirect)
  137. {
  138.    char NombProfile[270];
  139.    int Error= SinError;
  140.    HCURSOR Cursor= SetCursor(LoadCursor(NULL, IDC_WAIT));
  141.  
  142.    Actual= Primer = Ultimo= NULL;
  143.    StrUne(NombProfile,ProgDirect,"FUNCWIN.SUP");
  144.    ProfileStream *Profile= new ProfileStream(NombProfile);
  145.    if(Profile && !Profile->bad())
  146.    {
  147.       LeeEjemplos(Profile);
  148.       if(!Actual || Profile->bad())
  149.          Error= ErrorEjemplos2;
  150.    }
  151.    else
  152.       Error= ErrorEjemplos1;
  153.    if(Profile)
  154.       delete Profile;
  155.    SetCursor(Cursor);
  156.    if(Error)
  157.       Mensaje(NULL,Error);
  158.    else
  159.       return TRUE;
  160.    return FALSE;
  161. }
  162.  
  163. void TDlgEjemplos::LeeEjemplos(ProfileStream *Profile)
  164. {
  165.    TDatEjemplo *pEjemplo;
  166.  
  167.    while(!Profile->bad() && Profile->BuscaSeccion("Superf"))
  168.    {
  169.       pEjemplo= new TDatEjemplo;
  170.       if(Primer)
  171.       {
  172.          pEjemplo->Sig= Primer;
  173.          pEjemplo->Ant= Ultimo;
  174.          Primer->Ant= Ultimo->Sig= pEjemplo;
  175.       }
  176.       else
  177.          Actual= Primer= pEjemplo->Sig= pEjemplo->Ant= pEjemplo;
  178.       Ultimo= pEjemplo;
  179.  
  180.       TEjemplo *Datos= &pEjemplo->Datos;
  181.  
  182.       Profile->BuscaClave(NombreStr,Datos->Nombre,LongFunc,"Sin nombre");
  183.       Profile->BuscaClave(EcuXStr,  Datos->EcuX,  LongFunc,"");
  184.       Profile->BuscaClave(EcuYStr,  Datos->EcuY,  LongFunc,"");
  185.       Profile->BuscaClave(EcuZStr,  Datos->EcuZ,  LongFunc,"");
  186.       Profile->BuscaClave(IntvAStr, Datos->IntvA, LongFunc,"-1,1");
  187.       Profile->BuscaClave(IntvBStr, Datos->IntvB, LongFunc,"-1,1");
  188.       Profile->BuscaClave(EscalaStr,Datos->Escala,LongFunc,"10,10,10");
  189.       Profile->BuscaClave(OrigenStr,Datos->Origen,LongFunc,"0,0,0");
  190.       Profile->BuscaClave(AngIniStr,Datos->AngIni,LongFunc,"0,0,0");
  191.       Profile->BuscaClave(NodosStr, Datos->Nodos, LongFunc,"20,20");
  192.    }
  193. }
  194.  
  195. void TDlgEjemplos::DibujaEjemplo()
  196. {
  197.    TDatEcuPar EcuPar;
  198.  
  199.    Convierte(&EcuPar);
  200.    ChildWind->ModifSuperf(&EcuPar);
  201.    SendMessage(ChildWind->HWindow,WM_COMMAND,cmDibujar,NULL);
  202. }
  203.  
  204. void TDlgEjemplos::Muestra(TDatEjemplo *Ejemplo)
  205. {
  206.    Actual= Ejemplo;
  207.    TransferBuffer= &Ejemplo->Datos;
  208.    TransferData(TF_SETDATA);
  209.    if(IsWindowVisible(ChildWind->HWindow))
  210.       DibujaEjemplo();
  211. }
  212.  
  213. void TDlgEjemplos::IDSiguiente(RTMessage)
  214. {
  215.    if(Actual)
  216.       Muestra(Actual->Sig);
  217. }
  218.  
  219. void TDlgEjemplos::IDAnterior(RTMessage)
  220. {
  221.    if(Actual)
  222.       Muestra(Actual->Ant);
  223. }
  224.  
  225. void TDlgEjemplos::IDPrimer(RTMessage)
  226. {
  227.    if(Primer)
  228.       Muestra(Primer);
  229. }
  230.  
  231. void TDlgEjemplos::IDUltimo(RTMessage)
  232. {
  233.    if(Ultimo)
  234.       Muestra(Ultimo);
  235. }
  236.  
  237. void TDlgEjemplos::Convierte(TDatEcuPar *EcuPar)
  238. {
  239.    StrCpy(EcuPar->Nombre, Actual->Datos.Nombre);
  240.    StrCpy(EcuPar->Func.X, Actual->Datos.EcuX);
  241.    StrCpy(EcuPar->Func.Y, Actual->Datos.EcuY);
  242.    StrCpy(EcuPar->Func.Z, Actual->Datos.EcuZ);
  243.  
  244.    SeparaParam(Actual->Datos.IntvA,  EcuPar->Param.Intv.X.Inf,
  245.                                      EcuPar->Param.Intv.X.Sup);
  246.    SeparaParam(Actual->Datos.IntvB,  EcuPar->Param.Intv.Y.Inf,
  247.                                      EcuPar->Param.Intv.Y.Sup);
  248.    SeparaParam(Actual->Datos.Escala, EcuPar->Param.Escala.X,
  249.                                      EcuPar->Param.Escala.Y,
  250.                                      EcuPar->Param.Escala.Z);
  251.    SeparaParam(Actual->Datos.Origen, EcuPar->Param.Origen.X,
  252.                                      EcuPar->Param.Origen.Y,
  253.                                      EcuPar->Param.Origen.Z);
  254.    SeparaParam(Actual->Datos.AngIni, EcuPar->Param.AngIni.X,
  255.                                      EcuPar->Param.AngIni.Y,
  256.                                      EcuPar->Param.AngIni.Z);
  257.    SeparaParam(Actual->Datos.Nodos,  EcuPar->Param.Nodos.X,
  258.                                      EcuPar->Param.Nodos.Y);
  259. }
  260.  
  261. void TDlgEjemplos::IDDibujar(RTMessage)
  262. {
  263.    ShowWindow(ChildWind->HWindow,SW_SHOW);
  264.    DibujaEjemplo();
  265. }
  266.  
  267. void TDlgEjemplos::IDCopiar(RTMessage)
  268. {
  269.    TDatosEcuPar EcuPar;
  270.  
  271.    ChildWind->GetSuperfData(&EcuPar);
  272.    Convierte(&EcuPar.Superf);
  273.    SendMessage(Parent->HWindow,WM_COMMAND,cmCopiaEjemplo,(long)&EcuPar);
  274. }
  275.  
  276.